#define _CRT_SECURE_NO_WARNINGS
#include<vector>
#include<iostream>
using namespace std;
class BinarySearch {
public:
    int getPos(vector<int> A, int n, int val) {
        if (n <= 0) return -1;
        int left = 0, right = n - 1;
        while (left <= right)
        {
            int mid = (left + right) / 2;
            if (val == A[mid])
            {
                int i = mid - 1;
                for (; i >= 0 && val == A[i]; i--);

                return i + 1;
            }
            else if (val > A[mid])
                left = mid + 1;
            else
                right = mid - 1;
        }
        return -1;
    }
};
int main()
{
	vector<int> v;
	v.push_back(9);
	v.push_back(8);
	v.push_back(7);
	v.push_back(6);
	v.push_back(5);
	v.push_back(4);
	v.push_back(3);
	v.push_back(2);
	v.push_back(1);
    BinarySearch b;
    cout << b.getPos(v, 9, 1);
	return 0;
}